<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of physiographic_units_controller
 *
 * @author root
 */
class PhysiographicUnitsController extends AppController {

    //put your code here
    var $name = "PhysiographicUnits";

    function index() {
        $this->layout = "ajax";
        $id = $this->Session->read('proy_id');
       

        if ($id == "") {
            $this->Session->setFlash('No ha seleccionado Proyecto');
            $this->redirect(array('controller' => 'Proyects', 'action' => 'index'));
        } else {

            $this->PhysiographicUnit->recursive = -1;
            $this->set("units", $this->PhysiographicUnit->find('all', array('conditions' => array('PhysiographicUnit.proyect_id' => $id), 'fields' => array('PhysiographicUnit.descripcion' ,'PhysiographicUnit.id', 'PhysiographicUnit.area', 'PhysiographicUnit.clase_agrologica','PhysiographicUnit.topografia_relieve'))));
            $this->set('cod', $this->Session->read('cod'));
        }
    }
    function index2() {
        $this->layout = "ajax";
        $id = $this->Session->read('proy_id');
       

        if ($id == "") {
            $this->Session->setFlash('No ha seleccionado Proyecto');
            $this->redirect(array('controller' => 'Proyects', 'action' => 'index'));
        } else {

            $this->PhysiographicUnit->recursive = -1;
            $this->set("units", $this->PhysiographicUnit->find('all', array('conditions' => array('PhysiographicUnit.proyect_id' => $id), 'fields' => array('PhysiographicUnit.valor_adoptado' ,'PhysiographicUnit.id', 'PhysiographicUnit.area', 'PhysiographicUnit.clase_agrologica'))));
            $this->set('cod', $this->Session->read('cod'));
        }
    }

    function add() {
        $this->layout = "ajax";
        $id = $this->Session->read('proy_id');
        if ($id == "") {
            $this->Session->setFlash('No ha seleccionado Proyecto');
            $this->redirect(array('controller' => 'Proyects', 'action' => 'index'));
        } else {
            if (empty($this->data)) {
                $this->data['PhysiographicUnit']['proyect_id'] = $id;
            } else {
                if ($this->PhysiographicUnit->save($this->data)) {
                    $this->Session->setFlash('Unidad guardada exitosamente');
                    $this->redirect(array('controller' => 'PhysiographicUnits', 'action' => 'index'));
                }
            }
        }
    }

    function edit($id) {
        if (empty($this->data)) {
            $this->PhysiographicUnit->recursive=-1;
            $this->data = $this->PhysiographicUnit->find('first', array('conditions' => array('PhysiographicUnit.id' => $id)));
        
          
        } else {
            if ($this->PhysiographicUnit->save($this->data)) {
                $this->Session->setFlash('Unidad editada exitosamente');
                $this->redirect(array('controller' => 'PhysiographicUnits', 'action' => 'index'));
            }else{
                $this->data['PhysiographicUnit']['id']=$id;
            }
        }
    }
    function edit_valor($id) {
        if (empty($this->data)) {
            $this->data = $this->PhysiographicUnit->find('first', array('conditions' => array('PhysiographicUnit.id' => $id)));
        } else {
            if ($this->PhysiographicUnit->save($this->data)) {
                $this->Session->setFlash('UNIDAD EDITADA EXITOSAMENTE');
                $this->redirect(array('controller' => 'PhysiographicUnits', 'action' => 'index2'));
            }else{
                $this->data['PhysiographicUnit']['id']=$id;
            }
        }
    }
    function delete($id) {
        if ($this->PhysiographicUnit->delete($id)) {
            $this->Session->setFlash('Registro Borrado con éxito');
            $this->redirect(array('controller' => 'PhysiographicUnits', 'action' => 'index'));
        }
    }

}

?>
